using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.UI;
using OpenFlashChartLib;

namespace OpenFlashChartLib
{
    public class KeyValueList :RenderBase
    {
        private string _key;
        private ArrayList _values;

        public KeyValueList()
        {
            _values = new ArrayList();
        }

        public KeyValueList(string key)
        {
            _key = key;
            _values = new ArrayList();
        }

        public KeyValueList(string key, ICollection values)
        {
            _values = new ArrayList(values);
            _key = key;
        }

        public string Key
        {
            get { return _key; }
            set { _key = value; }
        }

        public ArrayList Values
        {
            get { return _values; }
            set { _values = value; }
        }

        public override void RenderContent(HtmlTextWriter writer)
        {
            writer.Write(_key);
            writer.Write("=");
            int i = 0;
            foreach (object o in _values)
            {
                if (i++ > 0)
                    writer.Write(",");
                writer.Write(Util.ToSafeString(o));
            }
        }

        public override void Render(HtmlTextWriter writer)
        {
            if (string.IsNullOrEmpty(_key) || _values.Count == 0)
                return;
            bool isEmpty = true;
            foreach (object o in _values)
            {
                if (!string.IsNullOrEmpty(o.ToString()))
                {
                    isEmpty = false;
                    break;
                }
            }
            if (isEmpty)
                return;
            base.Render(writer);
        }
    }
}
